package be.ipl.address.domaine;

import java.io.Serializable;
import java.util.Comparator;

import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.SecondaryTable;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

@SuppressWarnings("serial")
@Entity
@Table(name = "PERSONNES", schema = "ADRESSES")
@SecondaryTable(name = "GSM", schema = "ADRESSES")
public class Personne implements Serializable {

	@EmbeddedId
	private PersonnePK pk;
	@NotNull
	@Column(table = "GSM")
	private String gsm;
	@NotNull
	@Column(table = "GSM")
	private String operateur;
	@NotNull
	@Embedded
	private Adresse adresse = new Adresse();

	protected Personne() {
	}

	public Personne(String nom, String prenom, String pseudo) {
		this.pk = new PersonnePK(nom, prenom, pseudo);
	}

	public String getNom() {
		return pk.getNom();
	}

	public String getPrenom() {
		return pk.getPrenom();
	}

	public String getPseudo() {
		return pk.getPseudo();
	}

	public String getGsm() {
		return gsm;
	}

	public String getOperateur() {
		return operateur;
	}

	public void setGsm(String gsm) {
		this.gsm = gsm;
	}

	public void setOperateur(String operateur) {
		this.operateur = operateur;
	}

	public String getRueNumero() {
		return adresse.getRueNumero();
	}

	public String getCodePostal() {
		return adresse.getCodePostal();
	}

	public String getCommune() {
		return adresse.getCommune();
	}

	public void setRueNumero(String numero) {
		this.adresse.setRueNumero(numero);
	}

	public void setCodePostal(String codePostal) {
		this.adresse.setCodePostal(codePostal);
	}

	public void setCommune(String commune) {
		this.adresse.setCommune(commune);
	}

	public static class PersonnePseudoComparator implements
			Comparator<Personne>, Serializable {

		@Override
		public int compare(Personne p1, Personne p2) {
			return p1.getPrenom().compareTo(p2.getPseudo());
		}

	}

}
